import React, { useState, useEffect } from 'react'
import { View, Image } from '@tarojs/components'
import { AtList, AtListItem, AtModal, AtModalHeader, AtModalContent, AtModalAction } from "taro-ui"
import Taro, { useDidShow } from '@tarojs/taro'
import api from '../../../http/api'
const info: any = Taro.getStorageSync('info')
const uSchoolId = info ? JSON.parse(info).userInfo.uSchoolId : 0

import './index.less'
import "taro-ui/dist/style/components/list.scss";
import "taro-ui/dist/style/components/icon.scss";
import "taro-ui/dist/style/components/modal.scss";



export default (props: any) => {
  const [data, setData]: any = useState({
    id: 1,
    txt3: "18171873020",
    txt4: "13321280684",
    txt5: "3083487518",
    txt6: "",
    uSchoolId: 1
  })
  useDidShow(() => {
    api.version().then((res: any) => {
      const version = res.data
      if (version === 1) {
        api.concatInfo({ uSchoolId }).then((res: any) => {
          setData(res.data)
        })
        setList([
          {
            title: '新生专区订单',
            src: IMGSRC + 'ico6.png'
          },
          {
            title: 'U选商家订单',
            src: IMGSRC + 'ico6.png'
          },
          {
            title: '联系客服',
            src: IMGSRC + 'ico2.png'
          },
          {
            title: '商户入驻',
            src: IMGSRC + 'ico3.png'
          },
          {
            title: '设置',
            src: IMGSRC + 'ico5.png'
          }
        ])
      }
    })
  })
  const [list, setList] = useState([{
    title: '联系客服',
    src: IMGSRC + 'ico2.png'
  },])
  const navClick = (item: any) => {
    if (item.title === '商户入驻') {
      Taro.navigateTo({
        url: '/pages/businessEnter/index'
      })
    } else if (item.title === '联系客服') {
      setIsOpened(true)
    } else if (item.title === '设置') {
      Taro.navigateTo({
        url: '/pages/set/index'
      })
    } else if (item.title === '我的优惠券') {
      Taro.navigateTo({
        url: '/pages/myCard/index'
      })
    } else if (item.title === 'U选商家订单') {
      Taro.navigateTo({
        url: '/pages/uOrder/index'
      })
    }else if (item.title === '新生专区订单') {
      Taro.navigateTo({
        url: '/pages/nsOrder/index'
      })
    }
  }
  const [isOpened, setIsOpened] = useState(false)
  const onClose = () => {
    setIsOpened(false)
  }
  return (
    <View className='listNav'>
      <AtList>
        {
          list.map((item, i) => (
            <AtListItem
              className='navLi'
              onClick={() => { navClick(item) }}
              key={i}
              title={item.title}
              arrow='right'
              thumb={item.src}
            />
          ))
        }
      </AtList>
      <AtModal isOpened={isOpened} onClose={onClose}>
        <AtModalHeader>联系我们</AtModalHeader>
        <AtModalContent>
          <View className='concat'>TEL1：{data.txt3}</View>
          <View className='concat'>TEL2：{data.txt4}</View>
          <View className='concat'>QQ1：{data.txt5}</View>
          <View className='concat'>QQ2：{data.txt6}</View>
        </AtModalContent>
      </AtModal>
    </View>
  )
}
